/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.swirrel.listener;

import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;

import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 *
 * @author Gronau
 */
public class SwirrelTreeModelListener
    extends AbstractSwirrelListener implements TreeModelListener {

  private final MethodCall treeNodesChangedCall;
  private final MethodCall treeNodesInsertedCall;
  private final MethodCall treeNodesRemovedCall;
  private final MethodCall treeStructureChangedCall;

  public SwirrelTreeModelListener(
      MethodCall treeNodesChangedCall,
      MethodCall treeNodesInsertedCall,
      MethodCall treeNodesRemovedCall,
      MethodCall treeStructureChangedCall) {
    this.treeNodesChangedCall = treeNodesChangedCall;
    this.treeNodesInsertedCall = treeNodesInsertedCall;
    this.treeNodesRemovedCall = treeNodesRemovedCall;
    this.treeStructureChangedCall = treeStructureChangedCall;
    if (!checkSignature(treeNodesChangedCall, TreeModelEvent.class) ||
        !checkSignature(treeNodesInsertedCall, TreeModelEvent.class) ||
        !checkSignature(treeNodesRemovedCall, TreeModelEvent.class) ||
        !checkSignature(treeStructureChangedCall, TreeModelEvent.class)) {
      throw new SwirrelException(
          "Method must have none or one TreeModelEvent argument");
    }
  }

  public void treeNodesChanged(TreeModelEvent e) {
    call(treeNodesInsertedCall, e);
  }

  public void treeNodesInserted(TreeModelEvent e) {
    call(treeNodesChangedCall, e);
  }

  public void treeNodesRemoved(TreeModelEvent e) {
    call(treeNodesRemovedCall, e);
  }

  public void treeStructureChanged(TreeModelEvent e) {
    call(treeStructureChangedCall, e);
  }
}
